package org.gvp.generator.table;

import java.sql.Types;

/**
 * 数据类型转换类
 */
public class DataTypeConvert {


    /**
     * 将数据库类型转换为java类型
     * @param type sql数据表中的数据类型
     * @return java 数据类型
     */
    public static String convertToJava(int type){
        return switch (type){
            case Types.BIGINT -> "Long";
            case Types.INTEGER,Types.TINYINT -> "Integer";
            case Types.VARCHAR,Types.CHAR -> "String" ;
            case Types.BOOLEAN,Types.BIT -> "Boolean";
            case Types.DATE -> "LocalDate";
            case Types.TIME -> "LocalTime";
            case Types.TIMESTAMP -> "LocalDateTime";
            case Types.DECIMAL -> "Double";
            default -> "Object";
        } ;

    }

    public static String convertToTypescript(int type){
        return switch (type){
            case Types.INTEGER,Types.TINYINT,Types.BIGINT,Types.DECIMAL -> "number";
            case Types.VARCHAR,Types.CHAR -> "string" ;
            case Types.BOOLEAN,Types.BIT -> "boolean";
            case Types.DATE,Types.TIMESTAMP,Types.TIME -> "Date";
            default -> "object";
        } ;
    }
}
